package com.guangwei.lockscreenforelder.util

import java.lang.Exception
import java.text.SimpleDateFormat
import java.util.*

class TimeUtil @Throws(InstantiationException::class)
private constructor() {

    init {
        throw InstantiationException("This class is not for instantiation")
    }

    companion object {

        /**
         * @return "HH:mm:ss"
         */
        val curTime: String
            get() {
                val formatter = SimpleDateFormat("HH:mm:ss")
                val currentTime = Date()
                return formatter.format(currentTime)
            }

        /**
         * @return "yyyy-MM-dd HH:mm:ss"
         */
        val curDayTime: String
            get() {
                val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                val currentTime = Date()
                return formatter.format(currentTime)
            }

        /**
         * @return "yyyy-MM-dd"
         */
        val curDay: String
            get() {
                val formatter = SimpleDateFormat("yyyy-MM-dd")
                val currentTime = Date()
                return formatter.format(currentTime)
            }

        /**
         * @return "MM月dd日"
         */
        val curDayChinese: String
            get() {
                val formatter = SimpleDateFormat("MM月dd日")
                val currentTime = Date()
                return formatter.format(currentTime)
            }

        /**
         * @return "HH:mm"
         */
        val time: String
            get() {
                val timeString = curTime
                val timeArr = timeString.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
                return timeArr[0] + ":" + timeArr[1]
            }


        /**
         * @return "星期几"
         */
        val week: String
            get() {
                var list = arrayOf("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")
                var calendar: Calendar = Calendar.getInstance()
                calendar.time = Date()
                var index: Int = calendar.get(Calendar.DAY_OF_WEEK) - 1
                if (index < 0) {
                    index = 0
                }
                return list[index]
            }
    }
}
